package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.utils.JsonUtils;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.entity.SpuDetail;
import com.leyou.item.mapper.SpuDetailMapper;
import com.leyou.item.service.SpecParamService;
import com.leyou.item.service.SpuDetailService;
import com.leyou.item.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-05-28 12:07
 **/
@Service
public class SpuDetailServiceImpl  extends ServiceImpl<SpuDetailMapper, SpuDetail> implements SpuDetailService {

    @Autowired
    private SpecParamService specParamService;


    @Autowired
    private SpuService spuService;
    @Override
    public List<SpecParamDTO> querySpecValues(Long id, Boolean searching) {


        Map<Long, Object> map = JsonUtils.toMap(getById(id).getSpecification(), Long.class, Object.class);
        Long cid3 = spuService.getById(id).getCid3();
        List<SpecParam> paramList = specParamService.querySpecParams(cid3, null, searching);
        List<SpecParamDTO> paramDTOS = SpecParamDTO.convertEntityList(paramList);
        for (SpecParamDTO paramDTO : paramDTOS) {
            paramDTO.setValue(map.get(paramDTO.getId()));
        }
        return paramDTOS;
    }
}
